package com.flex.reflection.resolver;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

/**
 * 类型元信息
 * @author ganlt
 * @since 2019/09/20 15:28
 */
public class MetaType {

    private List<Type> internalTypes = new ArrayList<>();
    /**
     * 类型
     */
    private Type rawType;

    public MetaType() {}

    public MetaType(Type type) {
        this.rawType = type;
        initTypeResolver();
    }

    private void initTypeResolver() {

        resolveType();
    }

    public void addTypes(List<Type> types) {
        internalTypes.addAll(types);
    }

    public Type getTypes(Integer num) {
        return internalTypes.get(num);
    }

    public Type getLastType() {
        if (internalTypes.isEmpty()) {
            throw new RuntimeException("获取参数类型失败");
        }
        return internalTypes.get(internalTypes.size()-1);
    }

    public Type getFirstType() {
        if (internalTypes.isEmpty()) {
            throw new RuntimeException("获取参数类型失败");
        }
        return internalTypes.get(0);
    }

    /**
     * 解析类型
     */
    public void resolveType() {
        //解析一次

    }

    public int size() {
        return internalTypes.size();
    }

    public Type getRawType() {
        return rawType;
    }


}
